<?php

namespace app\index\validate;
use think\Validate;

class LoginValidate  extends Validate
{
    protected $rule =   [
        'email' => 'require|email',
        'password' => 'require',
        'type' => 'require|checkType',
        'code' => 'require',
        'pid' => 'require',
    ];

    protected $message  =   [
        'type.require' => '类型不能为空',
        'email.require' => '账号不能为空',
        'email.email' => '账号格式不正确',
        'password.require' => '密码不能为空',
        'pid.require' => '邀请链接不正确',
    ];

    protected $scene = [
        'login' => ['email', 'password'],
        'sms' => ['email', 'type'],
        'register' => ['email', 'code', 'password'],
    ];


    // 自定义验证规则
    protected function checkType($value)
    {
        $allowValues = ['register', 'password', 'forPass', 'pid', 'email'];
        return in_array($value, $allowValues, true) ? true : '类型值不在允许的范围内';
    }

}